package com.duolaibei.business.view.goods.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;

import com.duolaibei.business.view.goods.view.flowtag.OnInitSelectedPosition;

import java.util.List;

/**
 * Created by HanHailong on 15/10/19.
 */
public abstract class TagAdapter<T> extends BaseAdapter implements OnInitSelectedPosition {

    private final List<T> mDataList;
    private LayoutInflater mInflater;

    public TagAdapter(Context context, List<T> mDataList) {
        this.mDataList = mDataList;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (mDataList == null) {
            return 0;
        } else {
            return mDataList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        return mDataList != null ? mDataList.get(position) : 0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void onlyAddAll(List<T> datas) {
        mDataList.addAll(datas);
        notifyDataSetChanged();
    }

    public void clearAndAddAll(List<T> datas) {
        mDataList.clear();
        onlyAddAll(datas);
    }

    @Override
    public boolean isSelectedPosition(int position) {
        if (position % 2 == 0) {
            return true;
        }
        return false;
    }
}
